package com.changgou.order.listener;

import com.alibaba.fastjson.JSON;
import com.changgou.order.config.RabbitMQConfig;
import com.changgou.order.pojo.Order;
import com.changgou.order.service.OrderService;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @Author LQQ
 * @Date 2020/3/15 23:06
 * @Version 1.0
 */
@Component
public class OrderPayListener {
    @Autowired
    private OrderService orderService;

    @RabbitListener(queues = RabbitMQConfig.ORDER_PAY)
    public void receivePayMessage(String message) {
        System.out.println("订单服务收到了支付成功的消息: " + message);

        Map map = JSON.parseObject(message, Map.class);

        //调用业务层完成订单数据库的修改
        String orderId = (String) map.get("orderId");
        String transactionId = (String) map.get("transactionId");

        orderService.updatePayStatus(orderId,transactionId);


//
//        Order order = orderService.findById(orderId);
//        order.setOrderStatus("1");
//        orderService.update(order);
    }
}
